package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.TypeBean;
import com.pe1n.yangtaopai.page.type.view.activity.TypeActivity;

import java.util.List;

/**
 * Created by Pe1n on 2016/11/23.
 */

public class MyTypeAdapter extends RecyclerView.Adapter<MyTypeAdapter.MyViewHolder> {

    private Context mContext;
    private List<TypeBean.DataBean> mList;

    public MyTypeAdapter(Context mContext, List<TypeBean.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.inner_item_type_layout,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        Glide.with(mContext).load(mList.get(position).getImagePath())
                .placeholder(R.drawable.place_holder).into(holder.imageView);
        holder.textView.setText(mList.get(position).getTitle());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, TypeActivity.class);
                intent.putExtra("cid",mList.get(position).getTargetId());
                intent.putExtra("title",mList.get(position).getTitle());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView imageView;
        private TextView textView;

        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.iv_inner_type);
            textView = (TextView) itemView.findViewById(R.id.tv_inner_type);
        }
    }

}
